package org.hughie.springframework.context.annotation;

import cn.hutool.core.util.ClassUtil;
import org.hughie.springframework.beans.factory.config.BeanDefinition;
import org.hughie.springframework.stereotype.Component;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * 扫描包获取全部被@Component注解的类
 *
 * @author hughie.cheng
 * @since 2023/9/13
 */
public class ClassPathScanningCandidateComponentProvider {
    public Set<BeanDefinition> findCandidateComponents(String basePackage) {
        Set<BeanDefinition> candidate = new LinkedHashSet<>();
        Set<Class<?>> classes = ClassUtil.scanPackageByAnnotation(basePackage, Component.class);
        for (Class<?> clazz : classes) {
            candidate.add(new BeanDefinition(clazz));
        }
        return candidate;
    }
}
